package com.zax.servlet;

import com.zax.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//    }
    private GoodsService gService = new GoodsService();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.getWriter().append("Server at :").append(request.getContextPath());
        //取得条幅商品
        Map<String,Object> scrollGoods = gService.getScrollGoods();
        request.getSession().setAttribute("scrollGoods",scrollGoods);

        //取得热销商品
        List<Map<String,Object>> hotList = gService.getHotGoodsList();
        request.getSession().setAttribute("hotList" , hotList);

        //取得新品商品
        List<Map<String,Object>> newList = gService.getNewGoodsList();
        request.getSession().setAttribute("newList" , newList);

        //跳转到index.jsp
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
}
